#pragma once

class TwoDistanceEngine
{
private:
	struct Edge
	{
		int next;
		int to;
	};

	struct Graph
	{
		int head[200 + 5];
		Edge edge[2000];
		int edgeNum = 0;

		Graph(const Graph & g)
		{
			memcpy(head, g.head, sizeof(g.head));
			memcpy(edge, g.edge, sizeof(g.edge));
			edgeNum = g.edgeNum;
		}

		Graph()
		{
			memset(head, -1, sizeof(head));
			memset(edge, -1, sizeof(edge));
			edgeNum = 0;
		}
	};

	Graph left_down_right_up_raw;
	Graph left_up_right_down_raw;

	int u[6] = { -1, 0, 1, 1, 0, -1 };
	int v[6] = { 1, 1, 0, -1, -1, 0 };

	Board board;
	int size;

	void add(Graph & g, int u, int v)
	{
		g.edge[g.edgeNum].to = v;
		g.edge[g.edgeNum].next = g.head[u];
		g.head[u] = g.edgeNum;
		g.edgeNum++;
	}

	void two_dis(Graph & g, int s, int * out);

	void calc_left_down_right_up_raw();
	void calc_left_up_right_down_raw();

public:
	TwoDistanceEngine(const Board & board);

	void left_down(int * out);
	void left_up(int * out);
	void right_down(int * out);
	void right_up(int * out);

};